package com.snail.starter.commons.threadlocal;

public class UserContextUtils {

    private static final ThreadLocal<UserContext> CONTEXT = new ThreadLocal<>();

    public static void set(UserContext userContext) {
        CONTEXT.remove();
        CONTEXT.set(userContext);
    }

    public static UserContext get() {
        UserContext context = CONTEXT.get();
        if (null == context) {
            return UserContext.defaultContext();
        }
        return context;
    }

    public static void clear() {
        CONTEXT.remove();
    }

    public static void setOnlyUser(UserContext userContext) {
        CONTEXT.set(userContext);
    }


}